
module FamilyTreeApi
  module SummaryPerson
    class Event
      attr_accessor :type, :scope, :date, :place
      
      def parse(event_element)
        @type = event_element.attributes['type']
        date_element = event_element.find_first("fs:date",NS)
        place_element = event_element.find_first("fs:place",NS)
        @date = SummaryPerson::Date.parse date_element if date_element
        @place = SummaryPerson::Place.parse place_element if place_element
      end
      
      def self.parse(event_element)
        event = self.new
        event.parse event_element
        event
      end
    end
    
    class Date
      attr_accessor :original, :normalized
      
      def parse(date_element)
        norm_e = date_element.find_first("fs:normalized",NS)
        orig_e = date_element.find_first("fs:original",NS)
        @normalized = norm_e.content if norm_e
        @original = orig_e.content if orig_e
      end
      
      def self.parse(date_element)
        d = self.new
        d.parse date_element
        d
      end
    end
    
    class Place
      attr_accessor :original, :normalized, :place_id
      
      def parse(place_element)
        norm_e = place_element.find_first("fs:normalized",NS)
        orig_e = place_element.find_first("fs:original",NS)
        plac_a = norm_e.attributes["placeId"] if norm_e
        @normalized = norm_e.content if norm_e
        @original = orig_e.content if orig_e
        @place_id = plac_a if plac_a
      end
      
      def self.parse(place_element)
        p = self.new
        p.parse place_element
        p
      end
    end
  end
end